import os

#  构建关系-ID的字典，并返回关系的种类数(./data/)
class Relation:
    def __init__(self):
        self.dir = './data'

    def get_relation(self):
        relation_file = os.path.join(self.dir, 'relation2id.txt')
        rel2id = {}
        id2rel = {}
        with open(relation_file, 'r', encoding='utf-8') as fr:
            for line in fr:
                relation, id_s = line.strip().split()
                id_d = int(id_s)
                rel2id[relation] = id_d
                id2rel[id_d] = relation
        return rel2id, id2rel, len(rel2id)